import classNames from 'classnames'
import { InputProps } from '../Input'
import { ReactElement } from 'react'

export const DISPLAY_NAME_AUTO_COMPLETE = 'AutoComplete'

interface PresetSuggestItemData {
  value: string
}
export type SuggestItemData<T = {}> = T & PresetSuggestItemData

export interface AutoCompleteProps extends Omit<InputProps, 'onSelect'> {
  /**获取所有搜索建议的函数，接受异步的写法，函数输入值keyword为输入框的值, 返回一个搜索建议数组或promise */
  fetchSuggestions: (
    keyword: string
  ) => SuggestItemData[] | Promise<SuggestItemData[]>
  /**搜索建议被点击时调用的函数 */
  onSelect?: (item: SuggestItemData) => void
  /**搜索建议列表自定义渲染函数 */
  renderOption?: (item: SuggestItemData) => ReactElement
}

// 获取组件配置的class
export const getAutoCompleteClassNames = (
  props: AutoCompleteProps,
  extendClass?: () => Object
) => {
  // const {  } = props
  return classNames('auto-complete', extendClass && extendClass())
}
